#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <memory.h>  
#include "vcap_thread.h"
#include "libsapi_common.h"
#include "libsapi_video.h"
#include "drvsapi_video.h"
#include "drvsapi_video.h"

extern pthread_mutex_t vctrl_mutex;
extern pthread_cond_t  vctrl_start_ready;
extern pthread_cond_t  vctrl_over_ready;
extern pthread_t       vctrl_thread;

extern struct vctrl_params params;

void* vctrl_function()
{
	printf("i am vctrl function\n");

	pthread_mutex_lock(&vctrl_mutex);

	while(1){

		/*wait until receive a net commond*/
		pthread_cond_wait(&vctrl_start_ready, &vctrl_mutex);

		/*process the command*/
		switch(params.cmd){
		case APIVCMD_SET_EXPOSURE:
		case APIVCMD_SET_WHITEBALANCE:
		case APIVCMD_GET_WHITEBALANCE:
			printf("cmmddddddddddd\n");
			api_video_ctrl(params.cmd, &params);
			//sleep(1);
			break;

		case APIVCMD_CAP_VIDEO:
			vcap_process();
			break;

		default:
			break;

		}

		/*wakeup net thread to return process result*/
		pthread_cond_signal(&vctrl_over_ready);

	}

	pthread_mutex_unlock(&vctrl_mutex);
	pthread_cond_destroy(&vctrl_start_ready);
	pthread_cond_destroy(&vctrl_over_ready);

	pthread_exit(NULL);	
}
